using System;
using System.Collections.Generic;
using UnityEngine.Purchasing;
using Voodoo.Sauce.Internal.Analytics;

namespace Voodoo.Sauce.Internal.IAP
{
	internal class VoodooIAP
	{
		//private static List<IPurchaseDelegate> _purchaseDelegate;

		//private static ProductDescriptor[] _products;

		//private static StoreListener _storeListener;

		//public static void SetPurchaseDelegate(IPurchaseDelegate purchaseDelegate)
		//{
		//	//if (_purchaseDelegate == null)
		//	//{
		//	//	_purchaseDelegate = new List<IPurchaseDelegate>();
		//	//}
		//	//_purchaseDelegate.Add(purchaseDelegate);
		//}

		//public static void Init(ProductDescriptor[] products)
		//{
		//	if (products == null)
		//	{
		//		return;
		//	}
		//	VoodooLog.Log("VoodooIAP", "Intializing IAP system with " + products.Length + " products ...");
		//	if (products.Length != 0)
		//	{
		//		//if (_purchaseDelegate == null)
		//		//{
		//		//	//throw new Exception("No purchase delegate registered! You have to register one at the startup of your app!");
		//		//}
		//		//_products = products;
		//		//_storeListener = new StoreListener();
		//		//_storeListener.Init(products);
		//	}
		//}

		//public static void BuyProduct(string productId)
		//{
		//	if (_purchaseDelegate == null)
		//	{
		//		throw new Exception("No registered purchase delegate!");
		//	}
		//	_storeListener.BuyProduct(productId);
		//}

		//public static void RestorePurchases()
		//{
		//	if (_purchaseDelegate == null)
		//	{
		//		throw new Exception("No registered purchase delegate!");
		//	}
		//	_storeListener.RestorePurchases();
		//}

		//internal static void OnInitializeFailed(InitializationFailureReason reason)
		//{
		//	foreach (IPurchaseDelegate item in _purchaseDelegate)
		//	{
		//		item.OnInitializeFailure(reason);
		//	}
		//}

		//internal static void OnInitializeSuccess()
		//{
		//	foreach (IPurchaseDelegate item in _purchaseDelegate)
		//	{
		//		item.OnInitializeSuccess();
		//	}
		//}

		//internal static void ProcessPurchase(Product product, bool isPurchaseRestored)
		//{
		//	foreach (IPurchaseDelegate item in _purchaseDelegate)
		//	{
		//		item.OnPurchaseComplete(product.definition.id);
		//	}
		//	if (!isPurchaseRestored)
		//	{
		//		VoodooAnalytics.TrackPurchase(product, GetProductPriceInUSD(product.definition.id));
		//	}
		//}

		//internal static void OnPurchaseFailed(string productId, PurchaseFailureReason reason)
		//{
		//	foreach (IPurchaseDelegate item in _purchaseDelegate)
		//	{
		//		item.OnPurchaseFailure(productId, reason);
		//	}
		//}

		//internal static float GetProductPriceInUSD(string productId)
		//{
		//	for (int i = 0; i < _products.Length; i++)
		//	{
		//		if (_products[i].ProductId.Equals(productId))
		//		{
		//			return _products[i].PriceInUSD;
		//		}
		//	}
		//	throw new Exception("Unknown product : " + productId);
		//}

		//internal static string GetLocalizedProductPrice(string productId)
		//{
			//string localizedProductPrice = _storeListener.GetLocalizedProductPrice(productId);
			//if (string.IsNullOrEmpty(localizedProductPrice))
			//{
			//	return $"${GetProductPriceInUSD(productId)}";
			//}
			//return localizedProductPrice;
		//}
	}
}
